package xinyou.jh.net.scene
{
	import manager.SceneManager;
	
	import xinyou.jh.manager.GameManager;
	import xinyou.jh.net.JHReceiver;
	import xinyou.jh.net.SocketManager;
	import xinyou.jh.view.scene.MainScene;
	import xinyou.jh.vo.MainVO;
	import xinyou.net.SocketConnection;
	
	public class SceneReceiver extends JHReceiver
	{
		public function SceneReceiver(socket:SocketConnection)
		{
			super(socket);
		}
		override protected function initCallBack():void
		{
			addCallBack([151,3],getUserInfo);
			addCallBack([151,6],getEnterScene);
			addCallBack([103,4],getPlayerIn);
			addCallBack([103,5],getMonsterIn);
			addCallBack([103,1],getEnterSyn);
			addCallBack([103,33],getPlayerMove);
			addCallBack([103,7],getPlayerLeave);
			addCallBack([103,8],getMonsterLeave);//获取怪物详细信息
			addCallBack([103,28],getMonsterMove);//获取怪物移动信息
			addCallBack([101,7],getUserDetailInfo);//获取玩家详细信息
			addCallBack([114,10],getAttInfo);//获取属性广播消息
			addCallBack([151,12],getCreateRole);//获取创建角色结果
			addCallBack([151,14],getDelRole);//获取创建角色结果
		}
		public function getUserInfo(result:Object):void
		{
			SocketManager.getInstance().dispatchEvent(new SceneNetEvent(SceneNetEvent.USERINFO,result));
		}
		public function getEnterScene(result:Object):void
		{
			SocketManager.getInstance().dispatchEvent(new SceneNetEvent(SceneNetEvent.ENTERSCENE,result));
		}
		public function getPlayerIn(result:Object):void
		{
			GameManager.getInstance().updatePlayerList(result.playerInfo);
			SocketManager.getInstance().dispatchEvent(new SceneNetEvent(SceneNetEvent.PLAYERIN,result));
		}
		public function getMonsterIn(result:Object):void
		{
			t0("怪物进入，进入个数："+result.monsters.length);
			GameManager.getInstance().updateMonsterList(result.monsters.concat());
			SocketManager.getInstance().dispatchEvent(new SceneNetEvent(SceneNetEvent.MONSTERIN,result));
		}
		public function getMonsterLeave(result:Object):void
		{
			t0("怪物离开，离开个数："+result.monsters.length);
			SocketManager.getInstance().dispatchEvent(new SceneNetEvent(SceneNetEvent.MONSTERLEAVE,result));
		}
		public function getMonsterMove(result:Object):void
		{
			SocketManager.getInstance().dispatchEvent(new SceneNetEvent(SceneNetEvent.MONSTERMOVE,result));
		}
		public function getEnterSyn(result:Object):void
		{
			var gameManager:GameManager = GameManager.getInstance();
			gameManager.mainVO.x = result.m_nPosX;
			gameManager.mainVO.y = result.m_nPosY;
			result.m_nDir = result.m_nDir==0?1:result.m_nDir;
			gameManager.mainVO.dir = result.m_nDir;
			if(!(SceneManager.getInstance().curScene is MainScene))
			{
				gameManager.loadMain();
			}
		}
		public function getPlayerMove(result:Object):void
		{
			SocketManager.getInstance().dispatchEvent(new SceneNetEvent(SceneNetEvent.PLAYERMOVE,result));
		}
		public function getPlayerLeave(result:Object):void
		{
			SocketManager.getInstance().dispatchEvent(new SceneNetEvent(SceneNetEvent.PLAYERLEAVE,result));
		}
		public function getUserDetailInfo(result:Object):void
		{
			GameManager.getInstance().mainVO.dataRead_server_Detail(result);//补充玩家详细数据
		}
		public function getAttInfo(result:Object):void
		{
			var gameManager:GameManager = GameManager.getInstance();
			var mainVO:MainVO = gameManager.mainVO;
			gameManager.atts.push(result);
		}
		public function getCreateRole(result:Object):void
		{
			SocketManager.getInstance().dispatchEvent(new SceneNetEvent(SceneNetEvent.CREATEROLE,result));
		}
		public function getDelRole(result:Object):void
		{
			SocketManager.getInstance().dispatchEvent(new SceneNetEvent(SceneNetEvent.DELROLE,result));
		}
	}
}